{extend name="public/base"/}
{block name="style"}
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/newstyle.css">

{/block}
{block name="body"}
<div class="main-box clearfix">
	<header class="main-box-header clearfix">
		<div class="pull-left">
			<h2>{$meta_title}</h2>
		</div>
	</header>
	<div class="main-box-body clearfix">

		<form method="get" class="form form-horizontal" action="__URL__/editStr" enctype="multipart/form-data">
			<div class="form-group">
				<label class="col-lg-2 control-label">选择文件</label>
				<div class="col-lg-2">
					<select name="file_name" class="form-control">
						<option value="" >请选择</option>
						{volist name="filelist" id="file"}
						<option value="{$file['file_name']}" {if $file_name ==$file['file_name']}selected{/if}>{$file['file_name']}</option>
						{/volist}
					</select>
				</div>
				<label class="col-lg-2 control-label">选择语言</label>
				<div class="col-lg-3">
					<div class="checkbox-nice checkbox-inline">
						<input type="checkbox" name="language[]" value="ug_CN"  id="ug_CN" {volist name="language" id="item" key="key"} {if $item =="ug_CN"} checked="checked" {/if}{/volist}/>
						<label for="ug_CN" >维文</label>
					</div>
					<div class="checkbox-nice checkbox-inline">
						<input type="checkbox" name="language[]" value="kk_CN" id="kk_CN"  {volist name="language" id="item" key="key"} {if $item =="kk_CN"} checked="checked" {/if}{/volist} />
						<label for="kk_CN">哈文</label>
					</div>
					<div class="checkbox-nice checkbox-inline">
						<input type="checkbox" name="language[]" value="zh_CN" id="zh_CN"  {volist name="language" id="item" key="key"} {if $item =="zh_CN"} checked="checked" {/if}{/volist} />
						<label for="zh_CN">中文</label>
					</div>
					<div class="checkbox-nice checkbox-inline">
						<input type="checkbox" name="language[]" value="en_US" id="en_US"  {volist name="language" id="item" key="key"} {if $item =="en_US"} checked="checked" {/if}{/volist} />
						<label for="en_US">英文</label>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-lg-2 control-label">推荐翻译</label>
				<div class="col-lg-2">
					<select name="flag" class="form-control">
						<option value="-1" >请选择</option>
						<option value="0" {if $flag ==='0'}selected{/if}>否</option>
						<option value="1" {if $flag ==='1'}selected{/if}>是</option>
					</select>
				</div>
				<!--<label class="col-lg-2 control-label">人工审核</label>
				<div class="col-lg-2">
					<select name="check_flag" class="form-control">
						<option value="-1" >请选择</option>
						<option value="0" {if $check_flag ==='0'}selected{/if}>否</option>
						<option value="1" {if $check_flag ==='1'}selected{/if}>是</option>
					</select>
				</div>-->
			</div>
			<div class="form-group">
				<label class="col-lg-2 control-label">查询字段</label>
				<div class="col-lg-2">
					<input type="text" class="form-control" name="msgid" value="{$msgid}" >
				</div>
			</div>
			<div class="form-group">
				<div class="col-lg-offset-2 col-lg-10">
					<button class="btn btn-success submit-btn" type="submit" >确 定</button>
				</div>
			</div>
		</form>

		<div class="tabs-wrapper">
			<div class="tab-content">
				<div class="tab-pane fade in active" id="tab-home">
				{if condition="empty($list)"}
				<p>暂无数据！</p>
				{else/}
				<div class="table-responsive clearfix">
					<table class="table table-striped table-hover table-bordered">
						<thead>
							<tr>
								<th>源文本</th>
								<th>译文本</th>
								<th>语言</th>
								<th>文件</th>
								<th style="width: 80px;text-align: center;">推荐</th>
								<!--<th style="width: 80px;text-align: center;">审核</th>
								<th style="width: 80px;text-align: center;">推荐值</th>-->
								<th style="width: 100px;">操作</th>
							</tr>
						</thead>
						<tbody>
							{foreach name="list" item="items" key="key"}
							{foreach name="items" item="item" key="ks"}
							<tr> {php}$item['msgid']=stripslashes($item['msgid']);$item['msgstr']=stripslashes($item['msgstr']);{/php}
								{if $ks==0}
								<td id="rowspan{$item['msgid_id']}" rowspan="{php}echo count($items);{/php}"><a href="javascript:void(0);" class="xzclass"  msgid_id="{$item['msgid_id']}">[新增]</a>{$key}</td>{/if}
								<td  id="td{$item['id']}" class="{if $item['language'] == "ug_CN"||$language == "kk_CN"}uy_font{/if}">{$item['msgstr']}</td>
								<td >{$item['language']}</td>
								<td >{$item['file_name']}</td>
								<td >
									<div date="{$item['id']}"  class="switch switch-small mySwitch"  data-on-label="是" data-off-label="否">
										<input type="checkbox" {if $item['flag'] ==='1'}checked{/if} />
									</div>
								</td>
								<!--<td >
									<div date="{$item['id']}"  class="switch switch-small mySwitch2"  data-on-label="是" data-off-label="否">
										<input type="checkbox" {if $item['check_flag'] ==='1'}checked{/if} />
									</div>
								</td>
								<td ><input class="form-control gradeinput" date="{$item['id']}"  value="{$item['grade']}"></td>-->
								<td style="width: 40px;">
									<a href="javascript:void(0);" class="bjclass" id="bj{$item['id']}" date="{$item['id']}" msgid_id="{$item['msgid_id']}">编辑</a>/<a href="javascript:void(0);" class="scclass"  date="{$item['id']}" >删除</a>
								</td>
							</tr>
							<!--隐藏的编辑-->
							<tr id="id{$item['id']}" style="display: none"><td colspan="4">
								<textarea {if $item['language'] == "ug_CN"||$language == "kk_CN"}  style="direction: rtl;"{/if}  id="str{$item['id']}" class="form-control {if $item['language'] == "ug_CN"||$language == "kk_CN"}uy_font{/if}" date="{$item['id']}" name="msgstr">{$item['msgstr']}</textarea>
							</td>
								<td >
									<a href="javascript:void(0);" onclick="save({$item['id']})">保存</a>
								</td>
							</tr>
							<!--隐藏的新增-->
							{if $ks==0}
							<tr id="xzid{$item['msgid_id']}" style="display: none"><td >
								<textarea style="direction: rtl;"   class="form-control uy_font" date="{$item['id']}" name="msgstr{$item['msgid_id']}"></textarea>
							</td>
								<td style="width: 110px"><select name="language{$item['msgid_id']}" class="form-control addlanguage" msgid_id="{$item['msgid_id']}">
									<option value="ug_CN" >ug_CN</option>
									<option value="kk_CN" >kk_CN</option>
									<option value="zh_CN" >zh_CN</option>
									<option value="en_US" >en_US</option>
								</select></td>
								<td style="width: 100px"><input name="file_name{$item['msgid_id']}" class="form-control" value=""></td>
								<td >
									<div  name="flag{$item['msgid_id']}" class="switch switch-small"  data-on-label="是" data-off-label="否">
										<input   type="checkbox" checked />
									</div>
								</td>
								<!--<td >
									<div  name="check_flag{$item['msgid_id']}" class="switch switch-small"  data-on-label="是" data-off-label="否">
										<input   type="checkbox" checked />
									</div>
								</td>
								<td><input class="form-control " name="grade{$item['msgid_id']}"   value=""></td>-->
								<td >
									<a href="javascript:void(0);" onclick="add({$item['msgid_id']})">保存</a>/<a href="javascript:void(0);" onclick="cancel({$item['msgid_id']})">取消</a>
								</td>
							</tr>{/if}
							{/foreach}
							{/foreach}
						</tbody>
					</table>
					<div style="float: left;">{$page}</div>
					<select style="float: left;width: 100px;margin-top: 5px;margin-left: 10px;" id="nums" name="nums" class="form-control" >
						{foreach name="numslists" item="items" key="key"}
						<option value="{$items}" {if $nums ==$items}selected{/if}>{$items}</option>
						{/foreach}
					</select>

				</div>
				{/if}
				</div>
			</div>
		</div>
	</div>
</div>
{/block}


{block name="script"}
<script type="text/javascript">
	//修改每页显示数量
	$("#nums").change(function(){
		var nums=$(this).val();
		$.ajax({
			url:"/admin/msgset/editNums",
			data:{nums:nums},
			dataType:'json',
			type:'post',
			success:function(re){
				if(re.error==0){
					location.reload();
				}
			}
		})
	});

	$(".gradeinput").change(function(){
		var id=$(this).attr("date");
		var grade=$(this).val();
		$.ajax({
			url:"/admin/msgset/updateMsgstr",
			data:{id:id,grade:grade},
			dataType:'json',
			type:'post',
			success:function(re){
				if(re.error==0){
					alert(re.msg);
				}else if(re.error){
					alert(re.msg);
				}
			}
		})
	});
	//设置标准
	$('.mySwitch').on('switch-change', function (e, data) {
		var id=$(this).attr("date");
		var flag=0;
		if(data.value){
			flag=1;
		}
		$.ajax({
			url:"/admin/msgset/updateMsgstr",
			data:{id:id,flag:flag},
			dataType:'json',
			type:'post',
			success:function(re){
				if(re.error==0){
					alert(re.msg);
					location.reload();
				}else if(re.error){
					alert(re.msg);
				}
			}
		})
	});
	//设置人工审核
	$('.mySwitch2').on('switch-change', function (e, data) {
		var id=$(this).attr("date");
		var check_flag=0;
		if(data.value){
			check_flag=1;
		}
		$.ajax({
			url:"/admin/msgset/updateMsgstr",
			data:{id:id,check_flag:check_flag},
			dataType:'json',
			type:'post',
			success:function(re){
				if(re.error==0){
					alert(re.msg);
				}else if(re.error){
					alert(re.msg);
				}
			}
		})
	});
	//新增
	$(".xzclass").click(function(){
		var rowspantd='#rowspan'+$(this).attr("msgid_id");//获取合并的列数量
		var	rowspan=$(rowspantd).attr("rowspan");
		var name = '#xzid'+$(this).attr("msgid_id");//默认隐藏的增加翻译tr
		if($(name).is(':hidden')){
			rowspan++;
			$(name).show();
			$(rowspantd).attr('rowspan',rowspan);
		}
	});
	//取消新增
	function cancel(id) {
		var xzdiv=$('#xzid'+id);
		$(xzdiv).hide();
		var rowspantd='#rowspan'+id;//获取合并的列数量
		var	rowspan=$(rowspantd).attr("rowspan");
		rowspan--;
		$(rowspantd).attr('rowspan',rowspan);
	}
	//保存新增
	function add(id) {
		var msgid_id=id;
		var msgstr=$("textarea[name='msgstr"+id+"']").val();
		var language=$("select[name='language"+id+"']").val();
		var file_name=$("input[name='file_name"+id+"']").val();
		var grade=$("input[name='grade"+id+"']").val();
		var flag=0;
		var check_flag=0;
		if($("div[name='flag"+id+"']").children('div').hasClass('switch-on')){
			flag=1;
		}
		if($("div[name='check_flag"+id+"']").children('div').hasClass('switch-on')){
			check_flag=1;
		}
		$.ajax({
			url:"/admin/msgset/addMsgstr",
			data:{msgid_id:msgid_id,msgstr:msgstr,language:language,file_name:file_name,flag:flag,check_flag:check_flag,grade:grade},
			dataType:'json',
			type:'post',
			success:function(re){
				if(re.error==0){
					alert(re.msg);
					location.reload();
				}else if(re.error){
					alert(re.msg);
				}
			}
		})
	}
	//新增翻译里切换语言
	$(".addlanguage").change(function(){
		var language=$(this).val();
		var id=$(this).attr("msgid_id");
		if(language=="ug_CN"||language=="kk_CN"){
			$("textarea[name='msgstr"+id+"']").css("direction","rtl");
			$("textarea[name='msgstr"+id+"']").addClass("uy_font");
		}else{
			$("textarea[name='msgstr"+id+"']").css("direction","inherit");
			$("textarea[name='msgstr"+id+"']").removeClass("uy_font");
		}
	});
	//编辑
	$(".bjclass").click(function(){
		var rowspantd='#rowspan'+$(this).attr("msgid_id");//获取合并的列数量
		var	rowspan=$(rowspantd).attr("rowspan");
		var name = '#id'+$(this).attr("date");
		if($(this).html()=="编辑"){
			$(this).html("隐藏");
			$(name).show();
			rowspan++;
		}else{
			$(this).html("编辑");
			$(name).hide();
			rowspan--;
		}
		$(rowspantd).attr('rowspan',rowspan);
	});
	//删除
	$(".scclass").click(function(){
		var msg = "您真的确定要删除吗？";
		if (confirm(msg)==false){
			return;
		}
		var id=$(this).attr("date");
		$.ajax({    //ajax删除
			url:"/admin/msgset/delMsgstr",
			data:{id:id},
			dataType:'json',
			type:'post',
			success:function(re){
				if(re.error==0){
					alert(re.msg);
					location.reload();
				}else if(re.error){
					alert(re.msg);
				}
			}
		})
	});

	/*$("input[name='msgstr']").keydown(function(event) {
		if (event.keyCode == 13) {
			save($(this).attr('date'));
		}
	})*/
	function save(id) {
		var name = '#str'+id;
		var val=$(name).val();
		var textdiv=$('#id'+id);
		var bja=$('#bj'+id);
		var tdtext=$('#td'+id);

		var rowspantd='#rowspan'+bja.attr("msgid_id");//获取合并的列数量
		var	rowspan=$(rowspantd).attr("rowspan");
		$.ajax({    //ajax保存编辑
			url:"/admin/msgset/updateMsgstr",
			data:{id:id,msgstr:val},
			dataType:'json',
			type:'post',
			success:function(re){
				if(re.error==0){
					alert(re.msg);
					bja.html("编辑");
					textdiv.hide();
					tdtext.html(val);
					rowspan--;
					$(rowspantd).attr('rowspan',rowspan);
				}else if(re.error){
					alert(re.msg);
				}

			}
		})
	}

</script>
{/block}